package cn.jbolt.admin.xd.xdbillaccount;

import com.jfinal.plugin.activerecord.Page;
import cn.jbolt.extend.systemlog.ProjectSystemLogTargetType;
import cn.jbolt.core.service.base.JBoltBaseService;
import com.jfinal.kit.Kv;
import com.jfinal.kit.Okv;
import com.jfinal.kit.Ret;
import cn.jbolt.core.base.JBoltMsg;
import cn.jbolt.core.db.sql.Sql;
import cn.jbolt.common.model.xd.XdBillAccount;
/**
 * null管理
 * @ClassName: XdBillAccountService
 * @author: wzx
 * @date: 2025-06-15 11:44  
 */
public class XdBillAccountService extends JBoltBaseService<XdBillAccount> {
	private final XdBillAccount dao=new XdBillAccount().dao();
	@Override
	protected XdBillAccount dao() {
		return dao;
	}

	@Override
    protected int systemLogTargetType() {
        return ProjectSystemLogTargetType.NONE.getValue();
    }
		
	/**
	 * 后台管理数据查询
	 * @param pageNumber 第几页
	 * @param pageSize   每页几条数据
	 * @param keywords   关键词
	 * @param sortColumn  排序列名
	 * @param sortType  排序方式 asc desc
     * @param state state
     * @param isDeleted 是否删除
	 * @return
	 */
	public Page<XdBillAccount> getAdminDatas(int pageNumber, int pageSize, String keywords, String sortColumn, String sortType, Integer state, Boolean isDeleted) {
	    //创建sql对象
	    Sql sql = selectSql().page(pageNumber,pageSize);
	    //sql条件处理
        sql.eq(XdBillAccount.STATE,state);
        sql.eqBooleanToChar("is_deleted", isDeleted);
        //关键词模糊查询
		sql.like(XdBillAccount.NAME,keywords);
		//排序
		sql.orderBy(sortColumn,sortType);
		return paginate(sql);
	}
	
	/**
	 * 保存
	 * @param xdBillAccount
	 * @return
	 */
	public Ret save(XdBillAccount xdBillAccount) {
		if(xdBillAccount==null || isOk(xdBillAccount.getId())) {
			return fail(JBoltMsg.PARAM_ERROR);
		}
		boolean success=xdBillAccount.save();
		if(success) {
			//添加日志
			//addSaveSystemLog(xdBillAccount.getId(), JBoltUserKit.getUserId(), xdBillAccount.getName());
		}
		return ret(success);
	}
	
	/**
	 * 更新
	 * @param xdBillAccount
	 * @return
	 */
	public Ret update(XdBillAccount xdBillAccount) {
		if(xdBillAccount==null || notOk(xdBillAccount.getId())) {
			return fail(JBoltMsg.PARAM_ERROR);
		}
		//更新时需要判断数据存在
		XdBillAccount dbXdBillAccount=findById(xdBillAccount.getId());
		if(dbXdBillAccount==null) {return fail(JBoltMsg.DATA_NOT_EXIST);}
		boolean success=xdBillAccount.update();
		if(success) {
			//添加日志
			//addUpdateSystemLog(xdBillAccount.getId(), JBoltUserKit.getUserId(), xdBillAccount.getName());
		}
		return ret(success);
	}
	
	/**
	 * 删除数据后执行的回调
	 * @param xdBillAccount 要删除的model
	 * @param kv 携带额外参数一般用不上
	 * @return
	 */
	@Override
	protected String afterDelete(XdBillAccount xdBillAccount, Kv kv) {
		//addDeleteSystemLog(xdBillAccount.getId(), JBoltUserKit.getUserId(),xdBillAccount.getName());
		return null;
	}
	
	/**
	 * 检测是否可以删除
	 * @param xdBillAccount model
	 * @param kv 携带额外参数一般用不上
	 * @return
	 */
	@Override
	public String checkInUse(XdBillAccount xdBillAccount, Kv kv) {
		//这里用来覆盖 检测是否被其它表引用
		return null;
	}
	
	/**
	 * 恢复假删数据后执行的回调
	 * @param xdBillAccount 要恢复的model
	 * @return
	 */
	@Override
	protected String afterRecover(XdBillAccount xdBillAccount) {
		//addRecoverSystemLog(xdBillAccount.getId(), JBoltUserKit.getUserId(),xdBillAccount.getName());
		return null;
	}
	
}